/*
 * SessionDialog.java
 *
 * Created on August 27, 2007, 4:54 PM
 */

package org.oslo.ui;

import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import org.oslo.sessioninfo.domain.SessionInfo;
import org.oslo.ui.util.SessionModel;

/**
 *
 * @author  nl24167
 */
public class SessionDialog extends javax.swing.JDialog {
    
    /** Creates new form SessionDialog */
    public SessionDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

        jTable1 = new JTable(new SessionModel(OSLOView.getInstance().getSessions())) {
            @Override
            public String getToolTipText(MouseEvent e) {
                Point p = e.getPoint();
                int rowIndex = rowAtPoint(p);
                String desc = "Click to view the details of: " + OSLOView.getInstance().getSessions().get(rowIndex).getTitle();
                return desc;
            }
        };
        
        jTable1.addMouseListener(new MouseListener() {

            public void mouseClicked(MouseEvent e) {
                Point p = e.getPoint();
                int rowIndex = jTable1.rowAtPoint(p);
                String title = OSLOView.getInstance().getSessions().get(rowIndex).getTitle();
                System.out.println("Mouse clicked for: " + title);
                jTextPane1.setText(OSLOView.getInstance().getSessions().get(rowIndex).getDescription());
            }

            public void mousePressed(MouseEvent e) {
                //
            }

            public void mouseReleased(MouseEvent e) {
                //
            }

            public void mouseEntered(MouseEvent e) {
                //
            }

            public void mouseExited(MouseEvent e) {
                //
            }
            
        });
        
        jScrollPane1.setViewportView(jTable1);
              
               
        
//        List<SessionInfo> sessions = OSLOView.getInstance().getSessions();
//        StringBuilder builder = new StringBuilder();
//        for (SessionInfo sessionInfo : sessions) {
//            builder.append("Title: " + sessionInfo.getTitle()).append('\n');
//            String description =  sessionInfo.getDescription().replace('\n',' ').replace('\t', ' ');
//            builder.append("Description: " + description).append('\n');
//            builder.append("Time: " + sessionInfo.getStartTime()).append(" to ").append(sessionInfo.getEndTime()).append('\n');
//            builder.append("Speaker: "+ sessionInfo.getSpeakerName()).append('\n');
//        }
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        jScrollPane1.setViewportView(jTable1);

        jTextPane1.setContentType(application.Application.getInstance(org.oslo.ui.OSLOApp.class).getContext().getResourceMap(SessionDialog.class).getString("jTextPane1.contentType")); // NOI18N
        jScrollPane2.setViewportView(jTextPane1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables
    
}
